package com.lagou.rpc.consumer.config;

import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author liuc
 * @date 2021/6/3
 * @description
 **/
@Configuration
@EnableConfigurationProperties(RpcAddrProperties.class)
public class RpcConsumerConfig {

    @Resource
    private RpcAddrProperties rpcAddrProperties;

    @Bean
    public IUserService userService(){
        RpcClientProxy rpcClientProxy = new RpcClientProxy();
        rpcClientProxy.setAddrs(rpcAddrProperties.getAddrs());
        IUserService proxy = (IUserService) rpcClientProxy.createProxy(IUserService.class);
        return proxy;
    }
}
